// yb_mingpian/pages/member/map/index.js
var app = getApp(),
    core = app.requirejs("core");

Page({
    data: {
        markers: [{
            iconPath: "/yb_mingpian/static/images/red_position_icon.png",
            latitude: 34.6284500000,
            longitude: 112.4282100000,
            title: '',
            width: 50,
            height: 50,
            callout: {
                content: '',
                color: '#000',
                fontSize: 24,
                borderRadius: 5,
                display: 'ALWAYS',
                textAlign: 'center',
                padding: 10,
                // borderWidth:1,
                // borderColor:"#ddd",
                bgColor:'#fff'
            }
        }]
    },

    onLoad: function () {
        this.getTabbar();
    },

    onShow: function () {

    },

    // 获取tabbar
    getTabbar: function (){
        var that = this;

        core.get("index/tabbar", {}, function (res) {
            if (res.code == 0) {
                var tabbar = res.info.tabbar.list;
                if (tabbar.length > 0) {
                    for (var i = 0; i < tabbar.length; i++) {
                        if (tabbar[i].url == '/yb_mingpian/pages/member/map/index') {
                            that.setData({
                                "markers[0].latitude": tabbar[i].lat,
                                "markers[0].longitude": tabbar[i].lng
                            })

                            that.companyInfo();
                            break;
                        }
                    };
                } else {
                    core.alert('没有获取到信息')
                }
            } else {
                core.alert(res.msg)
            }
        })
    },

    // 获取公司信息
    companyInfo: function (){
        var that = this;
        core.get("User/About", {}, function (res) {
            console.log(res,'test2s')
            if (res.code == 0) {
                that.setData({
                    "markers[0].callout.content": res.info.name + '\n' + '地址：' + res.info.address
                })

                if (that.data.markers[0].latitude == '' || that.data.markers[0].longitude == '') {
                    that.setData({
                        "markers[0].latitude": res.info.lat ? res.info.lat : 34.6284500000,
                        "markers[0].longitude": res.info.lng ? res.info.lng : 112.4282100000,
                    })
                }
            } else {
                console.log("companyInfo:fail",res.msg)
            }
        })
    },
})